home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-17.z / elisp-17
Encoding:
GNU Info File  |  1994-08-02  |  50.4 KB  |  1,194 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Documentation,  Next: Files,  Prev: Modes,  Up: Top
  41.  
  42. Documentation
  43. *************
  44.  
  45.    GNU Emacs Lisp has convenient on-line help facilities, most of which
  46. derive their information from the documentation strings associated with
  47. functions and variables.  This chapter describes how to write good
  48. documentation strings for your Lisp programs, as well as how to write
  49. programs to access documentation.
  50.  
  51.    Note that the documentation strings for Emacs are not the same thing
  52. as the Emacs manual.  Manuals have their own source files, written in
  53. the Texinfo language; documentation strings are specified in the
  54. definitions of the functions and variables they apply to.  A collection
  55. of documentation strings is not sufficient as a manual because a good
  56. manual is not organized in that fashion; it is organized in terms of
  57. topics of discussion.
  58.  
  59. * Menu:
  60.  
  61. * Documentation Basics::      Good style for doc strings.
  62.                                 Where to put them.  How Emacs stores them.
  63. * Accessing Documentation::   How Lisp programs can access doc strings.
  64. * Keys in Documentation::     Substituting current key bindings.
  65. * Describing Characters::     Making printable descriptions of
  66.                                 non-printing characters and key sequences.
  67. * Help Functions::            Subroutines used by Emacs help facilities.
  68.  
  69. 
  70. File: elisp,  Node: Documentation Basics,  Next: Accessing Documentation,  Prev: Documentation,  Up: Documentation
  71.  
  72. Documentation Basics
  73. ====================
  74.  
  75.    A documentation string is written using the Lisp syntax for strings,
  76. with double-quote characters surrounding the text of the string.  This
  77. is because it really is a Lisp string object.  The string serves as
  78. documentation when it is written in the proper place in the definition
  79. of a function or variable.  In a function definition, the documentation
  80. string follows the argument list.  In a variable definition, the
  81. documentation string follows the initial value of the variable.
  82.  
  83.    When you write a documentation string, make the first line a complete
  84. sentence (or two complete sentences) since some commands, such as
  85. `apropos', print only the first line of a multi-line documentation
  86. string.  Also, you should not indent the second line of a documentation
  87. string, if you have one, because that looks odd when you use `C-h f'
  88. (`describe-function') or `C-h v' (`describe-variable').
  89.  
  90.    Documentation strings may contain several special substrings, which
  91. stand for key bindings to be looked up in the current keymaps when the
  92. documentation is displayed.  This allows documentation strings to refer
  93. to the keys for related commands and be accurate even when a user
  94. rearranges the key bindings.  (*Note Accessing Documentation::.)
  95.  
  96.    Within the Lisp world, a documentation string is kept with the
  97. function or variable that it describes:
  98.  
  99.    * The documentation for a function is stored in the function
  100.      definition itself (*note Lambda Expressions::.).  The function
  101.      `documentation' knows how to extract it.
  102.  
  103.    * The documentation for a variable is stored on the variable's
  104.      property list under the property name `variable-documentation'.
  105.      The function `documentation-property' knows how to extract it.
  106.  
  107.    However, to save space, the documentation for preloaded functions and
  108. variables (including primitive functions and autoloaded functions) are
  109. stored in the `emacs/etc/DOC-VERSION' file.  The
  110. `emacs/etc/DOC-VERSION' file can be accessed by both the
  111. `documentation' and the `documentation-property' functions, and the
  112. process is transparent to the user.  In this case, the documentation
  113. string is replaced with an integer offset into the
  114. `emacs/etc/DOC-VERSION' file.  Keeping the documentation strings out of
  115. the Emacs core image saves a significant amount of space.  *Note
  116. Building Emacs::.
  117.  
  118.    For information on the uses of documentation strings, see *Note
  119. Help: (emacs)Help.
  120.  
  121.    The `emacs/etc' directory contains two utilities that you can use to
  122. print nice-looking hardcopy for the file `emacs/etc/DOC-VERSION'.
  123. These are `sorted-doc.c' and `digest-doc.c'.
  124.  
  125. 
  126. File: elisp,  Node: Accessing Documentation,  Next: Keys in Documentation,  Prev: Documentation Basics,  Up: Documentation
  127.  
  128. Access to Documentation Strings
  129. ===============================
  130.  
  131.  - Function: documentation-property SYMBOL PROPERTY &optional VERBATIM
  132.      This function returns the documentation string that is recorded
  133.      SYMBOL's property list under property PROPERTY.  This uses the
  134.      function `get', but does more than that: it also retrieves the
  135.      string from the file `emacs/etc/DOC-VERSION' if necessary, and
  136.      runs `substitute-command-keys' to substitute the actual (current)
  137.      key bindings.
  138.  
  139.      If VERBATIM is non-`nil', that inhibits running
  140.      `substitute-command-keys'.  (The VERBATIM argument exists only as
  141.      of Emacs 19.)
  142.  
  143.           (documentation-property 'command-line-processed
  144.              'variable-documentation)
  145.                => "t once command line has been processed"
  146.  
  147.           (symbol-plist 'command-line-processed)
  148.                => (variable-documentation 188902)
  149.  
  150.  - Function: documentation FUNCTION &optional VERBATIM
  151.      This function returns the documentation string of FUNCTION.  This
  152.      function will access the documentation string if it is stored in
  153.      the `emacs/etc/DOC-VERSION' file.
  154.  
  155.      In addition, `documentation' runs `substitute-command-keys' on the
  156.      resulting string, so the value contains the actual (current) key
  157.      bindings.  (This is not done if VERBATIM is non-`nil'; the
  158.      VERBATIM argument exists only as of Emacs 19.)
  159.  
  160.      The function `documentation' signals a `void-function' error
  161.      unless FUNCTION has a function definition.  However, FUNCTION does
  162.      not need to have a documentation string.  If there is no
  163.      documentation string, `documentation' returns `nil'.
  164.  
  165.    Here is an example of using the two functions, `documentation' and
  166. `documentation-property', to display the documentation strings for
  167. several symbols in a `*Help*' buffer.
  168.  
  169.      (defun describe-symbols (pattern)
  170.        "Describe the Emacs Lisp symbols matching PATTERN.
  171.      All symbols that have PATTERN in their name are described
  172.      in the `*Help*' buffer."
  173.        (interactive "sDescribe symbols matching: ")
  174.        (let ((describe-func
  175.               (function
  176.                (lambda (s)
  177.  
  178.      ;; Print description of symbol.
  179.                  (if (fboundp s)             ; It is a function.
  180.                      (princ
  181.                       (format "%s\t%s\n%s\n\n" s
  182.                         (if (commandp s)
  183.                             (let ((keys (where-is-internal s)))
  184.                               (if keys
  185.                                   (concat
  186.                                    "Keys: "
  187.                                    (mapconcat 'key-description
  188.                                               keys " "))
  189.                                 "Keys: none"))
  190.                           "Function")
  191.  
  192.      (or (documentation s)
  193.                             "not documented"))))
  194.      
  195.                  (if (boundp s)              ; It is a variable.
  196.  
  197.      (princ
  198.                       (format "%s\t%s\n%s\n\n" s
  199.                         (if (user-variable-p s)
  200.                             "Option " "Variable")
  201.  
  202.      (or (documentation-property
  203.                               s 'variable-documentation)
  204.                             "not documented")))))))
  205.              sym-list)
  206.  
  207.      ;; Build a list of symbols that match pattern.
  208.          (mapatoms (function
  209.                     (lambda (sym)
  210.                       (if (string-match pattern (symbol-name sym))
  211.                           (setq sym-list (cons sym sym-list))))))
  212.  
  213.      ;; Display the data.
  214.          (with-output-to-temp-buffer "*Help*"
  215.            (mapcar describe-func (sort sym-list 'string<))
  216.            (print-help-return-message))))
  217.  
  218.    The `describe-symbols' function works like `apropos', but provides
  219. more information.
  220.  
  221.      (describe-symbols "goal")
  222.      
  223.      ---------- Buffer: *Help* ----------
  224.      goal-column     Option
  225.      *Semipermanent goal column for vertical motion, as set by C-x C-n, or nil.
  226.  
  227.      set-goal-column Command: C-x C-n
  228.      Set the current horizontal position as a goal for C-n and C-p.
  229.  
  230.      Those commands will move to this position in the line moved to
  231.      rather than trying to keep the same horizontal position.
  232.      With a non-nil argument, clears out the goal column
  233.      so that C-n and C-p resume vertical motion.
  234.      The goal column is stored in the variable `goal-column'.
  235.  
  236.      temporary-goal-column   Variable
  237.      Current goal column for vertical motion.
  238.      It is the column where point was
  239.      at the start of current run of vertical motion commands.
  240.      When the `track-eol' feature is doing its job, the value is 9999.
  241.      ---------- Buffer: *Help* ----------
  242.  
  243.  - Function: Snarf-documentation FILENAME
  244.      This function is used only during Emacs initialization, just before
  245.      the runnable Emacs is dumped.  It finds the file offsets of the
  246.      documentation strings stored in the file FILENAME, and records
  247.      them in the in-core function definitions and variable property
  248.      lists in place of the actual strings.  *Note Building Emacs::.
  249.  
  250.      Emacs finds the file FILENAME in the `emacs/etc' directory.  When
  251.      the dumped Emacs is later executed, the same file is found in the
  252.      directory `data-directory'.  Usually FILENAME is `"DOC-VERSION"'.
  253.  
  254.  - Variable: data-directory
  255.      This variable holds the name of the directory in which Emacs finds
  256.      certain data files that come with Emacs or are built as part of
  257.      building Emacs.  (In older Emacs versions, this directory was the
  258.      same as `exec-directory'.)
  259.  
  260. 
  261. File: elisp,  Node: Keys in Documentation,  Next: Describing Characters,  Prev: Accessing Documentation,  Up: Documentation
  262.  
  263. Substituting Key Bindings in Documentation
  264. ==========================================
  265.  
  266.    This function makes it possible for you to write a documentation
  267. string that enables a user to display information about the current,
  268. actual key bindings.  if you call `documentation' with non-`nil'
  269. VERBATIM, you might later call this function to do the substitution
  270. that you prevented `documentation' from doing.
  271.  
  272.  - Function: substitute-command-keys STRING
  273.      This function returns STRING with certain special substrings
  274.      replaced by the actual (current) key bindings.  This permits the
  275.      documentation to be displayed with accurate information about key
  276.      bindings.  (The key bindings may be changed by the user between
  277.      the time Emacs is built and the time that the documentation is
  278.      asked for.)
  279.  
  280.      This table lists the forms of the special substrings and what they
  281.      are replaced with:
  282.  
  283.     `\[COMMAND]'
  284.           is replaced either by a keystroke sequence that will invoke
  285.           COMMAND, or by `M-x COMMAND' if COMMAND is not bound to any
  286.           key sequence.
  287.  
  288.     `\{MAPVAR}'
  289.           is replaced by a summary of the value of MAPVAR, taken as a
  290.           keymap.  (The summary is made by `describe-bindings'.)
  291.  
  292.     `\<MAPVAR>'
  293.           makes this call to `substitute-command-keys' use the value of
  294.           MAPVAR as the keymap for future `\[COMMAND]' substrings.
  295.           This special string does not produce any replacement text
  296.           itself; it only affects the replacements done later.
  297.  
  298.      *Please note:* each `\' must be doubled when written in a string
  299.      in Emacs Lisp.
  300.  
  301.      Here are examples of the special substrings:
  302.  
  303.           (substitute-command-keys
  304.              "To abort recursive edit, type: \\[abort-recursive-edit]")
  305.           
  306.           => "To abort recursive edit, type: C-]"
  307.  
  308.           (substitute-command-keys
  309.              "The keys that are defined for the minibuffer here are:
  310.             \\{minibuffer-local-must-match-map}")
  311.           
  312.           => "The keys that are defined for the minibuffer here are:
  313.           
  314.           ?               minibuffer-completion-help
  315.           SPC             minibuffer-complete-word
  316.           TAB             minibuffer-complete
  317.           LFD             minibuffer-complete-and-exit
  318.           RET             minibuffer-complete-and-exit
  319.           C-g             abort-recursive-edit
  320.           "
  321.           (substitute-command-keys
  322.              "To abort a recursive edit from the minibuffer, type\
  323.           \\<minibuffer-local-must-match-map>\\[abort-recursive-edit].")
  324.           => "To abort a recursive edit from the minibuffer, type C-g."
  325.  
  326. 
  327. File: elisp,  Node: Describing Characters,  Next: Help Functions,  Prev: Keys in Documentation,  Up: Documentation
  328.  
  329. Describing Characters for Help Messages
  330. =======================================
  331.  
  332.    These functions convert events, key sequences or characters to
  333. textual descriptions.  These descriptions are useful for including
  334. arbitrary text characters or key sequences in messages, because they
  335. convert non-printing characters to sequences of printing characters.
  336. The description of a printing character is the character itself.
  337.  
  338.  - Function: key-description SEQUENCE
  339.      This function returns a string containing the Emacs standard
  340.      notation for the input events in SEQUENCE.  The argument SEQUENCE
  341.      may be a string, vector or list.  *Note Input Events::, for more
  342.      information about valid events.  See also the examples for
  343.      `single-key-description', below.
  344.  
  345.  - Function: single-key-description EVENT
  346.      This function returns a string describing EVENT in the standard
  347.      Emacs notation for keyboard input.  A normal printing character is
  348.      represented by itself, but a control character turns into a string
  349.      starting with `C-', a meta character turns into a string starting
  350.      with `M-', and space, linefeed, etc. are transformed to `SPC',
  351.      `LFD', etc.  A function key is represented by its name.  An event
  352.      which is a list is represented by the name of the symbol in the CAR
  353.      of the list.
  354.  
  355.           (single-key-description ?\C-x)
  356.                => "C-x"
  357.  
  358.           (key-description "\C-x \M-y \n \t \r \f123")
  359.                => "C-x SPC M-y SPC LFD SPC TAB SPC RET SPC C-l 1 2 3"
  360.  
  361.           (single-key-description 'C-mouse-1)
  362.                => "C-mouse-1"
  363.  
  364.  - Function: text-char-description CHARACTER
  365.      This function returns a string describing CHARACTER in the
  366.      standard Emacs notation for characters that appear in text--like
  367.      `single-key-description', except that control characters are
  368.      represented with a leading caret (which is how control characters
  369.      in Emacs buffers are usually displayed).
  370.  
  371.           (text-char-description ?\C-c)
  372.                => "^C"
  373.  
  374.           (text-char-description ?\M-m)
  375.                => "M-m"
  376.  
  377.           (text-char-description ?\C-\M-m)
  378.                => "M-^M"
  379.  
  380. 
  381. File: elisp,  Node: Help Functions,  Prev: Describing Characters,  Up: Documentation
  382.  
  383. Help Functions
  384. ==============
  385.  
  386.    Emacs provides a variety of on-line help functions, all accessible to
  387. the user as subcommands of the prefix `C-h'.  For more information
  388. about them, see *Note Help: (emacs)Help.  Here we describe some
  389. program-level interfaces to the same information.
  390.  
  391.  - Command: apropos REGEXP &optional DO-ALL PREDICATE
  392.      This function finds all symbols whose names contain a match for the
  393.      regular expression REGEXP, and returns a list of them.  It also
  394.      displays the symbols in a buffer named `*Help*', each with a
  395.      one-line description.
  396.  
  397.      If DO-ALL is non-`nil', then `apropos' also shows key bindings for
  398.      the functions that are found.
  399.  
  400.      If PREDICATE is non-`nil', it should be a function to be called on
  401.      each symbol that has matched REGEXP.  Only symbols for which
  402.      PREDICATE returns a non-`nil' value are listed or displayed.
  403.  
  404.      In the first of the following examples, `apropos' finds all the
  405.      symbols with names containing `exec'.  In the second example, it
  406.      finds and returns only those symbols that are also commands.  (We
  407.      don't show the output that results in the `*Help*' buffer.)
  408.  
  409.           (apropos "exec")
  410.                => (Buffer-menu-execute command-execute exec-directory
  411.               exec-path execute-extended-command execute-kbd-macro
  412.               executing-kbd-macro executing-macro)
  413.  
  414.           (apropos "exec" nil 'commandp)
  415.                => (Buffer-menu-execute execute-extended-command)
  416.  
  417.      The command `C-h a' (`command-apropos') calls `apropos', but
  418.      specifies a PREDICATE to restrict the output to symbols that are
  419.      commands.  The call to `apropos' looks like this:
  420.  
  421.           (apropos string t 'commandp)
  422.  
  423.  - Command: super-apropos REGEXP &optional DO-ALL
  424.      This function differs from `apropos' in that it searches
  425.      documentation strings as well as symbol names for matches for
  426.      REGEXP.  By default, it searches only the documentation strings,
  427.      and only those of functions and variables that are included in
  428.      Emacs when it is dumped.  If DO-ALL is non-`nil', it scans the
  429.      names and documentation strings of all functions and variables.
  430.  
  431.  - Command: help-command
  432.      This command is not a function, but rather a symbol which is
  433.      equivalent to the keymap called `help-map'.  It is defined in
  434.      `help.el' as follows:
  435.  
  436.           (define-key global-map "\C-h" 'help-command)
  437.           (fset 'help-command help-map)
  438.  
  439.  - Variable: help-map
  440.      The value of this variable is a local keymap for characters
  441.      following the Help key, `C-h'.
  442.  
  443.  - Function: print-help-return-message &optional FUNCTION
  444.      This function builds a string which is a message explaining how to
  445.      restore the previous state of the windows after a help command.
  446.      After building the message, it applies FUNCTION to it if FUNCTION
  447.      is non-`nil'.  Otherwise it calls `message' to display it in the
  448.      echo area.
  449.  
  450.      This function expects to be called inside a
  451.      `with-output-to-temp-buffer' special form, and expects
  452.      `standard-output' to have the value bound by that special form.
  453.      For an example of its use, see the example in the section
  454.      describing the `documentation' function (*note Accessing
  455.      Documentation::.).
  456.  
  457.      The constructed message will have one of the forms shown below.
  458.  
  459.           ---------- Echo Area ----------
  460.           Type C-x 1 to remove help window.
  461.           ---------- Echo Area ----------
  462.  
  463.           ---------- Echo Area ----------
  464.           Type C-x 4 b RET to restore old contents of help window.
  465.           ---------- Echo Area ----------
  466.  
  467.  - Variable: help-char
  468.      The value of this variable is the character that Emacs recognizes
  469.      as meaning Help.  When Emacs reads this character (which is
  470.      usually 8, the value of `C-h'), Emacs evaluates `(eval
  471.      help-form)', and displays the result if it is a string.  If
  472.      `help-form''s value is `nil', this character is read normally.
  473.  
  474.  - Variable: help-form
  475.      The value of this variable is a form to execute when the character
  476.      `help-char' is read.  If the form returns a string, that string is
  477.      displayed.  If `help-form' is `nil', then the help character is
  478.      not recognized.
  479.  
  480.      Entry to the minibuffer binds this variable to the value of
  481.      `minibuffer-help-form'.
  482.  
  483.  - Variable: prefix-help-command
  484.      This variable holds a command that prints help for a prefix
  485.      character.  The command is run when the user types the help
  486.      character after a prefix character.  The default value of
  487.      `prefix-help-command' is `describe-prefix-bindings'; that command
  488.      uses `this-command-keys' to find what prefix character was used,
  489.      then uses `describe-bindings' to describe it.
  490.  
  491.    The following two functions are found in the library `helper'.  They
  492. are for modes that want to provide help without relinquishing control,
  493. such as the "electric" modes.  You must load that library with
  494. `(require 'helper)' in order to use them.  Their names begin with
  495. `Helper' to distinguish them from the ordinary help functions.
  496.  
  497.  - Command: Helper-describe-bindings
  498.      This command pops up a window displaying a help buffer containing a
  499.      listing of all of the key bindings from both the local and global
  500.      keymaps.  It works by calling `describe-bindings'.
  501.  
  502.  - Command: Helper-help
  503.      This command provides help for the current mode.  It prompts the
  504.      user in the minibuffer with the message `Help (Type ? for further
  505.      options)', and then provides assistance in finding out what the key
  506.      bindings are, and what the mode is intended for.  It returns `nil'.
  507.  
  508.      This can be customized by changing the map `Helper-help-map'.
  509.  
  510. 
  511. File: elisp,  Node: Files,  Next: Backups and Auto-Saving,  Prev: Documentation,  Up: Top
  512.  
  513. Files
  514. *****
  515.  
  516.    In Emacs, you can find, create, view, save, and otherwise work with
  517. files and file directories.  This chapter describes most of the
  518. file-related functions of Emacs Lisp, but a few others are described in
  519. *Note Buffers::, and those related to backups and auto-saving are
  520. described in *Note Backups and Auto-Saving::.
  521.  
  522. * Menu:
  523.  
  524. * Visiting Files::           Reading files into Emacs buffers for editing.
  525. * Saving Buffers::           Writing changed buffers back into files.
  526. * Reading from Files::       Reading files into buffers without visiting.
  527. * Writing to Files::         Writing new files from parts of buffers.
  528. * File Locks::               Locking and unlocking files, to prevent
  529.                                simultaneous editing by two people.
  530. * Information about Files::  Testing existence, accessibility, size of files.
  531. * Contents of Directories::  Getting a list of the files in a directory.
  532. * Create/Delete Dirs::         Creating and Deleting Directories.
  533. * Changing File Attributes:: Renaming files, changing protection, etc.
  534. * File Names::               Decomposing and expanding file names.
  535. * Magic File Names::         Defining "magic" special handling
  536.                    for certain file names.
  537.  
  538. 
  539. File: elisp,  Node: Visiting Files,  Next: Saving Buffers,  Up: Files
  540.  
  541. Visiting Files
  542. ==============
  543.  
  544.    Visiting a file means reading a file into a buffer.  Once this is
  545. done, we say that the buffer is "visiting" that file, and call the file
  546. "the visited file" of the buffer.
  547.  
  548.    A file and a buffer are two different things.  A file is information
  549. recorded permanently in the computer (unless you delete it).  A buffer,
  550. on the other hand, is information inside of Emacs that will vanish at
  551. the end of the editing session (or when you kill the buffer).  Usually,
  552. a buffer contains information that you have copied from a file; then we
  553. say the buffer is visiting that file.  The copy in the buffer is what
  554. you modify with editing commands.  Such changes to the buffer do not
  555. change the file; therefore, to make the changes permanent, you must
  556. "save" the buffer, which means copying the altered buffer contents back
  557. into the file.
  558.  
  559.    In spite of the distinction between files and buffers, people often
  560. refer to a file when they mean a buffer and vice-versa.  Indeed, we say,
  561. "I am editing a file," rather than, "I am editing a buffer which I will
  562. soon save as a file of the same name."  Humans do not usually need to
  563. make the distinction explicit.  When dealing with a computer program,
  564. however, it is good to keep the distinction in mind.
  565.  
  566. * Menu:
  567.  
  568. * Visiting Functions::         The usual interface functions for visiting.
  569. * Subroutines of Visiting::    Lower-level subroutines that they use.
  570.  
  571. 
  572. File: elisp,  Node: Visiting Functions,  Next: Subroutines of Visiting,  Up: Visiting Files
  573.  
  574. Functions for Visiting Files
  575. ----------------------------
  576.  
  577.    This section describes the functions normally used to visit files.
  578. For historical reasons, these functions have names starting with
  579. `find-' rather than `visit-'.  *Note Buffer File Name::, for functions
  580. and variables that access the visited file name of a buffer or that
  581. find an existing buffer by its visited file name.
  582.  
  583.  - Command: find-file FILENAME
  584.      This function reads the file FILENAME into a buffer and displays
  585.      that buffer in the selected window so that the user can edit it.
  586.  
  587.      The body of the `find-file' function is very simple and looks like
  588.      this:
  589.  
  590.           (switch-to-buffer (find-file-noselect filename))
  591.  
  592.      (See `switch-to-buffer' in *Note Displaying Buffers::.)
  593.  
  594.      When `find-file' is called interactively, it prompts for FILENAME
  595.      in the minibuffer.
  596.  
  597.  - Function: find-file-noselect FILENAME
  598.      This function is the guts of all the file-visiting functions.  It
  599.      reads a file into a buffer and returns the buffer.  You may then
  600.      make the buffer current or display it in a window if you wish, but
  601.      this function does not do so.
  602.  
  603.      If no buffer is currently visiting FILENAME, then one is created
  604.      and the file is visited.  If FILENAME does not exist, the buffer
  605.      is left empty, and `find-file-noselect' displays the message `New
  606.      file' in the echo area.
  607.  
  608.      If a buffer is already visiting FILENAME, then the
  609.      `find-file-noselect' function uses that buffer rather than creating
  610.      a new one.  However, it does verify that the file has not changed
  611.      since it was last visited or saved in that buffer.  If the file
  612.      has changed, then this function asks the user whether to reread
  613.      the changed file.  If the user says `yes', any changes previously
  614.      made in the buffer are lost.
  615.  
  616.      The `find-file-noselect' function calls `after-find-file' after
  617.      the file is read in (*note Subroutines of Visiting::.).  The
  618.      `after-find-file' function sets the buffer major mode, parses local
  619.      variables, warns the user if there exists an auto-save file more
  620.      recent than the file just visited, and finishes by running the
  621.      functions in `find-file-hooks'.
  622.  
  623.      The `find-file-noselect' function returns the buffer that is
  624.      visiting the file FILENAME.
  625.  
  626.           (find-file-noselect "/etc/fstab")
  627.                => #<buffer fstab>
  628.  
  629.  - Command: find-alternate-file FILENAME
  630.      This function reads the file FILENAME into a buffer and selects
  631.      it, killing the buffer current at the time the command is run.  It
  632.      is useful if you have visited the wrong file by mistake, so that
  633.      you can get rid of the buffer that you did not want to create, at
  634.      the same time as you visit the file you intended.
  635.  
  636.      When this function is called interactively, it prompts for
  637.      FILENAME.
  638.  
  639.  - Command: find-file-other-window FILENAME
  640.      This function visits the file FILENAME and displays its buffer in
  641.      a window other than the selected window.  It may use another
  642.      existing window or split a window; see *Note Displaying Buffers::.
  643.  
  644.      When this function is called interactively, it prompts for
  645.      FILENAME.
  646.  
  647.  - Command: find-file-read-only FILENAME
  648.      This function visits the file named FILENAME and selects its
  649.      buffer, just like `find-file', but it marks the buffer as
  650.      read-only.  *Note Read Only Buffers::, for related functions and
  651.      variables.
  652.  
  653.      When this function is called interactively, it prompts for
  654.      FILENAME.
  655.  
  656.  - Command: view-file FILENAME
  657.      This function views FILENAME in View mode, returning to the
  658.      previous buffer when done.  View mode is a mode that allows you to
  659.      skim rapidly through the file but does not let you modify it.
  660.  
  661.      After loading the file, `view-file' runs the normal hook
  662.      `view-hook' using `run-hooks'.  *Note Hooks::.
  663.  
  664.      When this function is called interactively, it prompts for
  665.      FILENAME.
  666.  
  667.  - Variable: find-file-hooks
  668.      The value of this variable is a list of functions to be called
  669.      after a file is visited.  The file's local-variables specification
  670.      (if any) will have been processed before the hooks are run.  The
  671.      buffer visiting the file is current when the hook functions are
  672.      run.
  673.  
  674.      This variable could be a normal hook, but we think that renaming it
  675.      would not be advisable.
  676.  
  677.  - Variable: find-file-not-found-hooks
  678.      The value of this variable is a list of functions to be called when
  679.      `find-file' or `find-file-noselect' is passed a nonexistent
  680.      FILENAME.  These functions are called as soon as the error is
  681.      detected.  `buffer-file-name' is already set up.  The functions are
  682.      called in the order given, until one of them returns non-`nil'.
  683.  
  684.      This is not a normal hook because the values of the functions are
  685.      used and they may not all be run.
  686.  
  687. 
  688. File: elisp,  Node: Subroutines of Visiting,  Prev: Visiting Functions,  Up: Visiting Files
  689.  
  690. Subroutines of Visiting
  691. -----------------------
  692.  
  693.    The `find-file-noselect' function uses the `create-file-buffer' and
  694. `after-find-file' functions as subroutines.  Sometimes it is useful to
  695. call them directly.
  696.  
  697.  - Function: create-file-buffer FILENAME
  698.      This function creates a suitably named buffer for visiting
  699.      FILENAME, and returns it.  The string FILENAME (sans directory) is
  700.      used unchanged if that name is free; otherwise, a string such as
  701.      `<2>' is appended to get an unused name.  See also *Note Creating
  702.      Buffers::.
  703.  
  704.      *Please note:* `create-file-buffer' does *not* associate the new
  705.      buffer with a file and does not make it the current buffer.
  706.  
  707.           (create-file-buffer "foo")
  708.                => #<buffer foo>
  709.           (create-file-buffer "foo")
  710.                => #<buffer foo<2>>
  711.           (create-file-buffer "foo")
  712.                => #<buffer foo<3>>
  713.  
  714.      This function is used by `find-file-noselect'.  It uses
  715.      `generate-new-buffer' (*note Creating Buffers::.).
  716.  
  717.  - Function: after-find-file &optional ERROR WARN
  718.      This function is called by `find-file-noselect' and by the default
  719.      revert function (*note Reverting::.).  It sets the buffer major
  720.      mode, and parses local variables (*note Auto Major Mode::.).
  721.  
  722.      If there was an error in opening the file, the calling function
  723.      should pass ERROR a non-`nil' value.  In that case,
  724.      `after-find-file' issues a warning: `(New File)'.  Note that, for
  725.      serious errors, you would not even call `after-find-file'.  Only
  726.      "file not found" errors get here with a non-`nil' ERROR.
  727.  
  728.      If WARN is non-`nil', then this function issues a warning if an
  729.      auto-save file exists and is more recent than the visited file.
  730.  
  731.      The last thing `after-find-file' does is call all the functions in
  732.      `find-file-hooks'.
  733.  
  734. 
  735. File: elisp,  Node: Saving Buffers,  Next: Reading from Files,  Prev: Visiting Files,  Up: Files
  736.  
  737. Saving Buffers
  738. ==============
  739.  
  740.    When you edit a file in Emacs, you are actually working on a buffer
  741. that is visiting that file--that is, the contents of the file are
  742. copied into the buffer and the copy is what you edit.  Changes to the
  743. buffer do not change the file until you "save" the buffer, which means
  744. copying the contents of the buffer into the file.
  745.  
  746.  - Command: save-buffer &optional BACKUP-OPTION
  747.      This function saves the contents of the current buffer in its
  748.      visited file if the buffer has been modified since it was last
  749.      visited or saved.  Otherwise it does nothing.
  750.  
  751.      `save-buffer' is responsible for making backup files.  Normally,
  752.      BACKUP-OPTION is `nil', and `save-buffer' makes a backup file only
  753.      if this is the first save or if the buffer was previously
  754.      modified.  Other values for BACKUP-OPTION request the making of
  755.      backup files in other circumstances:
  756.  
  757.         * With an argument of 4 or 64, reflecting 1 or 3 `C-u''s, the
  758.           `save-buffer' function marks this version of the file to be
  759.           backed up when the buffer is next saved.
  760.  
  761.         * With an argument of 16 or 64, reflecting 2 or 3 `C-u''s, the
  762.           `save-buffer' function unconditionally backs up the previous
  763.           version of the file before saving it.
  764.  
  765.  - Command: save-some-buffers &optional SAVE-SILENTLY-P EXITING
  766.      This command saves some modified file-visiting buffers.  Normally
  767.      it asks the user about each buffer.  But if SAVE-SILENTLY-P is
  768.      non-`nil', it saves all the file-visiting buffers without querying
  769.      the user.
  770.  
  771.      The optional EXITING argument, if non-`nil', requests this
  772.      function to offer also to save certain other buffers that are not
  773.      visiting files.  These are buffers that have a non-`nil' local
  774.      value of `buffer-offer-save'.  (A user who says yes to saving one
  775.      of these is asked to specify a file name to use.)  The
  776.      `save-buffers-kill-emacs' function passes a non-`nil' value for
  777.      this argument.
  778.  
  779.  - Variable: buffer-offer-save
  780.      When this variable is non-`nil' in a buffer, Emacs offers to save
  781.      the buffer on exit even if the buffer is not visiting a file.  The
  782.      variable is automatically local in all buffers.  Normally, Mail
  783.      mode (used for editing outgoing mail) sets this to `t'.
  784.  
  785.  - Command: write-file FILENAME
  786.      This function writes the current buffer into file FILENAME, makes
  787.      the buffer visit that file, and marks it not modified.  The buffer
  788.      is renamed to correspond to FILENAME unless that name is already
  789.      in use.
  790.  
  791.  - Variable: write-file-hooks
  792.      The value of this variable is a list of functions to be called
  793.      before writing out a buffer to its visited file.  If one of them
  794.      returns non-`nil', the file is considered already written and the
  795.      rest of the functions are not called, nor is the usual code for
  796.      writing the file executed.
  797.  
  798.      If a function in `write-file-hooks' returns non-`nil', it is
  799.      responsible for making a backup file (if that is appropriate).  To
  800.      do so, execute the following code:
  801.  
  802.           (or buffer-backed-up (backup-buffer))
  803.  
  804.      You might wish to save the file modes value returned by
  805.      `backup-buffer' and use that to set the mode bits of the file that
  806.      you write.  This is what `basic-save-buffer' does when it writes a
  807.      file in the usual way.
  808.  
  809.      Here is an example showing how to add an element to
  810.      `write-file-hooks' but avoid adding it twice:
  811.  
  812.           (or (memq 'my-write-file-hook write-file-hooks)
  813.               (setq write-file-hooks
  814.                     (cons
  815.                     'my-write-file-hook write-file-hooks)))
  816.  
  817.  - Variable: local-write-file-hooks
  818.      This works just like `write-file-hooks', but it is intended to be
  819.      made local to particular buffers.  It's not a good idea to make
  820.      `write-file-hooks' local to a buffer--use this variable instead.
  821.  
  822.      The variable is marked as a permanent local, so that changing the
  823.      major mode does not alter a buffer-local value.  This is
  824.      convenient for packages that read "file" contents in special ways,
  825.      and set up hooks to save the data in a corresponding way.
  826.  
  827.  - Variable: write-contents-hooks
  828.      This works just like `write-file-hooks', but it is intended to be
  829.      used for hooks that pertain to the contents of the file, as
  830.      opposed to hooks that pertain to where the file came from.
  831.  
  832.  - Variable: after-save-hook
  833.      This normal hook runs after a buffer has been saved in its visited
  834.      file.
  835.  
  836.  - Variable: file-precious-flag
  837.      If this variable is non-`nil', then `save-buffer' protects against
  838.      I/O errors while saving by writing the new file to a temporary
  839.      name instead of the name it is supposed to have, and then renaming
  840.      it to the intended name after it is clear there are no errors.
  841.      This procedure prevents problems such as a lack of disk space from
  842.      resulting in an invalid file.
  843.  
  844.      (This feature worked differently in older Emacs versions.)
  845.  
  846.      Some modes set this non-`nil' locally in particular buffers.
  847.  
  848.  - User Option: require-final-newline
  849.      This variable determines whether files may be written out that do
  850.      *not* end with a newline.  If the value of the variable is `t',
  851.      then Emacs silently puts a newline at the end of the file whenever
  852.      the buffer being saved does not already end in one.  If the value
  853.      of the variable is non-`nil', but not `t', then Emacs asks the
  854.      user whether to add a newline each time the case arises.
  855.  
  856.      If the value of the variable is `nil', then Emacs doesn't add
  857.      newlines at all.  `nil' is the default value, but a few major modes
  858.      set it to `t' in particular buffers.
  859.  
  860. 
  861. File: elisp,  Node: Reading from Files,  Next: Writing to Files,  Prev: Saving Buffers,  Up: Files
  862.  
  863. Reading from Files
  864. ==================
  865.  
  866.    You can copy a file from the disk and insert it into a buffer using
  867. the `insert-file-contents' function.  Don't use the user-level command
  868. `insert-file' in a Lisp program, as that sets the mark.
  869.  
  870.  - Function: insert-file-contents FILENAME &optional VISIT BEG END
  871.      This function inserts the contents of file FILENAME into the
  872.      current buffer after point. It returns a list of the absolute file
  873.      name and the length of the data inserted.  An error is signaled if
  874.      FILENAME is not the name of a file that can be read.
  875.  
  876.      If VISIT is non-`nil', it also marks the buffer as unmodified and
  877.      sets up various fields in the buffer so that it is visiting the
  878.      file FILENAME: these include the buffer's visited file name and
  879.      its last save file modtime.  This feature is used by
  880.      `find-file-noselect' and you should probably not use it yourself.
  881.  
  882.      If BEG and END are non-`nil', they should be integers specifying
  883.      the portion of the file to insert.  In this case, VISIT must be
  884.      `nil'.  For example,
  885.  
  886.           (insert-file-contents filename nil 0 500)
  887.  
  888.      inserts the first 500 characters of a file.
  889.  
  890.    If you want to pass a file name to another process so that another
  891. program can read the file, see the function `file-local-copy' in *Note
  892. Magic File Names::.
  893.  
  894. 
  895. File: elisp,  Node: Writing to Files,  Next: File Locks,  Prev: Reading from Files,  Up: Files
  896.  
  897. Writing to Files
  898. ================
  899.  
  900.    You can write the contents of a buffer, or part of a buffer, directly
  901. to a file on disk using the `append-to-file' and `write-region'
  902. functions.  Don't use these functions to write to files that are being
  903. visited; that could cause confusion in the mechanisms for visiting.
  904.  
  905.  - Command: append-to-file START END FILENAME
  906.      This function appends the contents of the region delimited by
  907.      START and END in the current buffer to the end of file FILENAME.
  908.      If that file does not exist, it is created.  This function returns
  909.      `nil'.
  910.  
  911.      An error is signaled if FILENAME specifies a nonwritable file, or
  912.      a nonexistent file in a directory where files cannot be created.
  913.  
  914.  - Command: write-region START END FILENAME &optional APPEND VISIT
  915.      This function writes the region (of the current buffer) delimited
  916.      by START and END into the file specified by FILENAME.
  917.  
  918.      If START is a string, then `write-region' writes or appends that
  919.      string, rather than text from the buffer.
  920.  
  921.      If APPEND is non-`nil', then the region is appended to the
  922.      existing file contents (if any).
  923.  
  924.      If VISIT is `t', then Emacs establishes an association between the
  925.      buffer and the file: the buffer is then visiting that file.  It
  926.      also sets the last file modification time for the current buffer to
  927.      FILENAME's modtime, and marks the buffer as not modified.  This
  928.      feature is used by `write-file' and you should probably not use it
  929.      yourself.
  930.  
  931.      If VISIT is a string, it specifies the file name to visit.  This
  932.      way, you can write the data to one file (FILENAME) while recording
  933.      the buffer as visiting another file (VISIT).  The argument VISIT
  934.      is used in the echo area message and also for file locking; VISIT
  935.      is stored in `buffer-file-name'.  This feature is used to
  936.      implement `file-precious-flag'; don't use it yourself unless you
  937.      really know what you're doing.
  938.  
  939.      Normally, `write-region' displays a message `Wrote file FILENAME'
  940.      in the echo area.  If VISIT is neither `t' nor `nil' nor a string,
  941.      then this message is inhibited.  This feature is useful for
  942.      programs that use files for internal purposes, files which the
  943.      user does not need to know about.
  944.  
  945. 
  946. File: elisp,  Node: File Locks,  Next: Information about Files,  Prev: Writing to Files,  Up: Files
  947.  
  948. File Locks
  949. ==========
  950.  
  951.    When two users edit the same file at the same time, they are likely
  952. to interfere with each other.  Emacs tries to prevent this situation
  953. from arising by recording a "file lock" when a file is being modified.
  954. Emacs can then detect the first attempt to modify a buffer visiting a
  955. file that is locked by another Emacs job, and ask the user what to do.
  956.  
  957.    File locks do not work properly when multiple machines can share
  958. file systems, such as with NFS.  Perhaps a better file locking system
  959. will be implemented in the future.  When file locks do not work, it is
  960. possible for two users to make changes simultaneously, but Emacs can
  961. still warn the user who saves second.  Also, the detection of
  962. modification of a buffer visiting a file changed on disk catches some
  963. cases of simultaneous editing; see *Note Modification Time::.
  964.  
  965.  - Function: file-locked-p FILENAME
  966.      This function returns `nil' if the file FILENAME is not locked by
  967.      this Emacs process.  It returns `t' if it is locked by this Emacs,
  968.      and it returns the name of the user who has locked it if it is
  969.      locked by someone else.
  970.  
  971.           (file-locked-p "foo")
  972.                => nil
  973.  
  974.  - Function: lock-buffer &optional FILENAME
  975.      This function locks the file FILENAME, if the current buffer is
  976.      modified.  The argument FILENAME defaults to the current buffer's
  977.      visited file.  Nothing is done if the current buffer is not
  978.      visiting a file, or is not modified.
  979.  
  980.  - Function: unlock-buffer
  981.      This function unlocks the file being visited in the current buffer,
  982.      if the buffer is modified.  If the buffer is not modified, then
  983.      the file should not be locked, so this function does nothing.  It
  984.      also does nothing if the current buffer is not visiting a file.
  985.  
  986.  - Function: ask-user-about-lock FILE OTHER-USER
  987.      This function is called when the user tries to modify FILE, but it
  988.      is locked by another user name OTHER-USER.  The value it returns
  989.      tells Emacs what to do next:
  990.  
  991.         * A value of `t' tells Emacs to grab the lock on the file.  Then
  992.           this user may edit the file and OTHER-USER loses the lock.
  993.  
  994.         * A value of `nil' tells Emacs to ignore the lock and let this
  995.           user edit the file anyway.
  996.  
  997.         * This function may instead signal a `file-locked' error, in
  998.           which case the change to the buffer which the user was about
  999.           to make does not take place.
  1000.  
  1001.           The error message for this error looks like this:
  1002.  
  1003.                error--> File is locked: FILE OTHER-USER
  1004.  
  1005.           where `file' is the name of the file and OTHER-USER is the
  1006.           name of the user who has locked the file.
  1007.  
  1008.      The default definition of this function asks the user to choose
  1009.      what to do.  If you wish, you can replace the `ask-user-about-lock'
  1010.      function with your own version that decides in another way.  The
  1011.      code for its usual definition is in `userlock.el'.
  1012.  
  1013. 
  1014. File: elisp,  Node: Information about Files,  Next: Contents of Directories,  Prev: File Locks,  Up: Files
  1015.  
  1016. Information about Files
  1017. =======================
  1018.  
  1019.    The functions described in this section are similar in as much as
  1020. they all operate on strings which are interpreted as file names.  All
  1021. have names that begin with the word `file'.  These functions all return
  1022. information about actual files or directories, so their arguments must
  1023. all exist as actual files or directories unless otherwise noted.
  1024.  
  1025.    Most of the file-oriented functions take a single argument,
  1026. FILENAME, which must be a string.  The file name is expanded using
  1027. `expand-file-name', so `~' is handled correctly, as are relative file
  1028. names (including `../').  Environment variable substitutions, such as
  1029. `$HOME', are not recognized by these functions.  *Note File Name
  1030. Expansion::.
  1031.  
  1032. * Menu:
  1033.  
  1034. * Testing Accessibility::   Is a given file readable?  Writable?
  1035. * Kinds of Files::          Is it a directory?  A symbolic link?
  1036. * Truenames::            Eliminating symbolic links from a file name.
  1037. * File Attributes::         How large is it?  Any other names?  Etc.
  1038.  
  1039. 
  1040. File: elisp,  Node: Testing Accessibility,  Next: Kinds of Files,  Up: Information about Files
  1041.  
  1042. Testing Accessibility
  1043. ---------------------
  1044.  
  1045.    These functions test for permission to access a file in specific
  1046. ways.
  1047.  
  1048.  - Function: file-exists-p FILENAME
  1049.      This function returns `t' if a file named FILENAME appears to
  1050.      exist.  This does not mean you can necessarily read the file, only
  1051.      that you can find out its attributes.  (On Unix, this is true if
  1052.      the file exists and you have execute permission on the containing
  1053.      directories, regardless of the protection of the file itself.)
  1054.  
  1055.      If the file does not exist, or if fascist access control policies
  1056.      prevent you from finding the attributes of the file, this function
  1057.      returns `nil'.
  1058.  
  1059.  - Function: file-readable-p FILENAME
  1060.      This function returns `t' if a file named FILENAME exists and you
  1061.      can read it.  It returns `nil' otherwise.
  1062.  
  1063.           (file-readable-p "files.texi")
  1064.                => t
  1065.           (file-exists-p "/usr/spool/mqueue")
  1066.                => t
  1067.           (file-readable-p "/usr/spool/mqueue")
  1068.                => nil
  1069.  
  1070.  - Function: file-executable-p FILENAME
  1071.      This function returns `t' if a file named FILENAME exists and you
  1072.      can execute it.  It returns `nil' otherwise.  If the file is a
  1073.      directory, execute permission means you can access files inside
  1074.      the directory.
  1075.  
  1076.  - Function: file-writable-p FILENAME
  1077.      This function returns `t' if FILENAME can be written or created by
  1078.      you.  It is writable if the file exists and you can write it.  It
  1079.      is creatable if the file does not exist, but the specified
  1080.      directory does exist and you can write in that directory.
  1081.      `file-writable-p' returns `nil' otherwise.
  1082.  
  1083.      In the third example below, `foo' is not writable because the
  1084.      parent directory does not exist, even though the user could create
  1085.      it.
  1086.  
  1087.           (file-writable-p "~rms/foo")
  1088.                => t
  1089.           (file-writable-p "/foo")
  1090.                => nil
  1091.           (file-writable-p "~rms/no-such-dir/foo")
  1092.                => nil
  1093.  
  1094.  - Function: file-accessible-directory-p DIRNAME
  1095.      This function returns `t' if you have permission to open existing
  1096.      files in directory DIRNAME; otherwise (and if there is no such
  1097.      directory), it returns `nil'.  The value of DIRNAME may be either
  1098.      a directory name or the file name of a directory.
  1099.  
  1100.      Example: after the following,
  1101.  
  1102.           (file-accessible-directory-p "/foo")
  1103.                => nil
  1104.  
  1105.      we can deduce that any attempt to read a file in `/foo/' will give
  1106.      an error.
  1107.  
  1108.  - Function: file-newer-than-file-p FILENAME1 FILENAME2
  1109.      This functions returns `t' if the file FILENAME1 is newer than
  1110.      file FILENAME2.  If FILENAME1 does not exist, it returns `nil'.
  1111.      If FILENAME2 does not exist, it returns `t'.
  1112.  
  1113.      You can use `file-attributes' to get a file's last modification
  1114.      time as a list of two numbers.  *Note File Attributes::.
  1115.  
  1116.      In the following example, assume that the file `aug-19' was
  1117.      written on the 19th, and `aug-20' was written on the 20th.  The
  1118.      file `no-file' doesn't exist at all.
  1119.  
  1120.           (file-newer-than-file-p "aug-19" "aug-20")
  1121.                => nil
  1122.           (file-newer-than-file-p "aug-20" "aug-19")
  1123.                => t
  1124.           (file-newer-than-file-p "aug-19" "no-file")
  1125.                => t
  1126.           (file-newer-than-file-p "no-file" "aug-19")
  1127.                => nil
  1128.  
  1129. 
  1130. File: elisp,  Node: Kinds of Files,  Next: Truenames,  Prev: Testing Accessibility,  Up: Information about Files
  1131.  
  1132. Distinguishing Kinds of Files
  1133. -----------------------------
  1134.  
  1135.    This section describes how to distinguish directories and symbolic
  1136. links from ordinary files.
  1137.  
  1138.  - Function: file-symlink-p FILENAME
  1139.      If FILENAME is a symbolic link, the `file-symlink-p' function
  1140.      returns the file name to which it is linked.  This may be the name
  1141.      of a text file, a directory, or even another symbolic link, or of
  1142.      no file at all.
  1143.  
  1144.      If FILENAME is not a symbolic link (or there is no such file),
  1145.      `file-symlink-p' returns `nil'.
  1146.  
  1147.           (file-symlink-p "foo")
  1148.                => nil
  1149.           (file-symlink-p "sym-link")
  1150.                => "foo"
  1151.           (file-symlink-p "sym-link2")
  1152.                => "sym-link"
  1153.           (file-symlink-p "/bin")
  1154.                => "/pub/bin"
  1155.  
  1156.  
  1157.  - Function: file-directory-p FILENAME
  1158.      This function returns `t' if FILENAME is the name of an existing
  1159.      directory, `nil' otherwise.
  1160.  
  1161.           (file-directory-p "~rms")
  1162.                => t
  1163.           (file-directory-p "~rms/lewis/files.texi")
  1164.                => nil
  1165.           (file-directory-p "~rms/lewis/no-such-file")
  1166.                => nil
  1167.           (file-directory-p "$HOME")
  1168.                => nil
  1169.           (file-directory-p
  1170.            (substitute-in-file-name "$HOME"))
  1171.                => t
  1172.  
  1173. 
  1174. File: elisp,  Node: Truenames,  Next: File Attributes,  Prev: Kinds of Files,  Up: Information about Files
  1175.  
  1176. Truenames
  1177. ---------
  1178.  
  1179.    The "truename" of a file is the name that you get by following
  1180. symbolic links until none remain, then expanding to get rid of `.' and
  1181. `..' as components.  Strictly speaking, a file need not have a unique
  1182. truename; the number of distinct truenames a file has is equal to the
  1183. number of hard links to the file.  However, truenames are useful
  1184. because they eliminate symbolic links as a cause of name variation.
  1185.  
  1186.  - Function: file-truename FILENAME
  1187.      The function `file-truename' returns the true name of the file
  1188.      FILENAME.  This is the name that you get by following symbolic
  1189.      links until none remain.  The argument must be an absolute file
  1190.      name.
  1191.  
  1192.    *Note Buffer File Name::, for related information.
  1193.  
  1194.